package com.cynoware.busappmas.ui;


import com.cynoware.busappmas.R;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;



public class PopDialog extends Dialog{

	public PopDialog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	public PopDialog(Context context, int theme) {
		super(context, theme);
	}
	public static class Builder {
		
		private Context context;
		private TextView popinfo;
		private Button popbtn;
		
		public Builder(Context context){
			this.context=context;
		}
		
			
		public Handler getHandler(){
			return handler;
		}
		public PopDialog create() {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			final PopDialog dialog = new PopDialog(context,R.style.Dialog);
			View layout = inflater.inflate(R.layout.popdialog, null);
			dialog.addContentView(layout, new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
			popinfo=(TextView) layout.findViewById(R.id.poptxt);
			popbtn=(Button) layout.findViewById(R.id.popok);
			popbtn.setOnClickListener(new View.OnClickListener(){
				@Override
				public void onClick(View arg0) {
					dialog.dismiss();
				}
			});
			return dialog;
			}
		
		 @SuppressLint("HandlerLeak")
		private Handler handler = new Handler() {
			 public void handleMessage(Message msg) {
				 super.handleMessage(msg); 
				 switch(msg.what){
				 case 1:
					 String info=(String) msg.obj;
					 popinfo.setText(context.getResources().getString(R.string.str_being_replicating)+info+"  ...");
					 popbtn.setVisibility(View.GONE);
					 break;
				 case 2:
					 popinfo.setText(context.getResources().getString(R.string.str_copy_complete));
					 popbtn.setVisibility(View.VISIBLE);
					 break;
				 case 3:
					 popinfo.setText(context.getResources().getString(R.string.str_please_insert_u_disk));
					 popbtn.setVisibility(View.VISIBLE);
					 break;
				 }
				 }
			 };
		}
	

}
